package com.gxgeek.springbootwebfluxlearning;

import com.gxgeek.springbootwebfluxlearning.event.MyEvent;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.data.mongodb.core.CollectionOptions;
import org.springframework.data.mongodb.core.MongoOperations;

@SpringBootApplication
public class SpringbootWebfluxLearningApplication {

	public static void main(String[] args) {
		SpringApplication.run(SpringbootWebfluxLearningApplication.class, args);
	}


	@Bean   // 1
	public CommandLineRunner initData(MongoOperations mongo) {  // 2
		return (String... args) -> {    // 3
			mongo.dropCollection(MyEvent.class);    // 4
//			mongo.createCollection(MyEvent.class, CollectionOptions.empty().size(200).capped()); // 5
			mongo.createCollection(MyEvent.class, CollectionOptions.empty().maxDocuments(200).size(100000).capped()); // 6:maxDocuments限制了记录条数，size限制容量且是必须定义的，
		};
	}

}
